# -*- coding: utf-8 -*-
import os
import shutil


def main(source_folder, destination_folder):
    for i in range(1, 6):
        # 确保目标文件夹存在，如果不存在则创建
        if not os.path.exists(destination_folder):
            os.makedirs(destination_folder)

        # 遍历源文件夹内的所有文件和子文件夹
        for root, dirs, files in os.walk(source_folder):
            # 构建目标文件夹路径
            relative_path = os.path.relpath(root, source_folder)
            destination_path = os.path.join(destination_folder, relative_path)

            # 确保目标文件夹存在，如果不存在则创建
            if not os.path.exists(destination_path):
                os.makedirs(destination_path)

            # 移动文件
            for file in files:
                source_file_path = os.path.join(root, file)
                destination_file_path = os.path.join(destination_path, file)
                if os.path.splitext(source_file_path)[1] != ".xlsx":
                    try:
                        shutil.move(os.path.abspath(source_file_path), destination_file_path)
                    except FileNotFoundError:
                        print(f"文件没有找到{os.path.abspath(source_file_path)}，移动到{destination_file_path}")
            if not any(files) and  not any(dirs):
                    shutil.rmtree(os.path.abspath(root))
